<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
// use Hash;
// use App\Http\Requests\IndexController;

class IndexController extends Controller
{
    //主页展示
    public function index()
    {
        //限制查询条数
       // $video= DB::table('video')->offset(0)->limit(5)->get();
        //限制查询条数(适用于分页)
        // $video= DB::table('video')->paginate(6);
          
        //热播电影
    	$video = DB::table('video')
            ->join('type', 'video.tid', '=', 'type.id')
            ->where('video.id','=','1 && type.id = 1' )->first();
            // dd($video);

    	//获取数据
    	$videos = DB::table('video')
                ->join('type', 'video.tid', '=', 'type.id')
                ->where('video.id','>','1 && type.id = 1')
                ->orderBy('video.click', 'desc')
                ->paginate(6);

        //热播电视剧
        $tv = DB::table('video')
            ->join('type', 'video.tid', '=', 'type.id')
            ->where('video.tid','=','2')
            ->first();
            // dd($video);

        //获取数据
        $tvs = DB::table('video')
                ->join('type', 'video.tid', '=', 'type.id')
                ->where('video.id','>','1')
                ->orwhere('video.tid','=','2')
                ->orderBy('video.click', 'desc')
                ->paginate(6);

                 // dd($tvs);

    	$ad = DB::table('ad')->first();

    	//解析模板
    	return view('home.index',['video'=>$video,'videos'=>$videos,'tv'=>$tv,'tvs'=>$tvs,'ad'=>$ad]);
    }

    public function vlist()
    {

    	$videos = DB::table('video')
            ->join('type', 'video.tid', '=', 'type.id')
            ->where('video.id','>','1')
            ->get();
    	$ad = DB::table('ad')->first();

    	//解析模板
    	return view('home/layout.index',['videos'=>$videos,'ad'=>$ad]);
    }

}
